package com.xasqkj.seethedoctorwithphone.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.xasqkj.seethedoctorwithphone.R;
import com.xasqkj.seethedoctorwithphone.fragment.FragmentProperty;
import com.xasqkj.seethedoctorwithphone.fragment.FragmentPropertyManager;
import com.zhy.android.percent.support.PercentLinearLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    FragmentPropertyManager fragmentPropertyManager;
    PercentLinearLayout linearLayoutHome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initListener();
        fragmentPropertyManager.showFragment(new FragmentProperty("Hello 医生", R.layout.fragment_main));
    }

    private void initView() {
        fragmentPropertyManager = new FragmentPropertyManager(this);
        linearLayoutHome = (PercentLinearLayout) findViewById(R.id.linearlayoutHome);
    }

    private void initListener() {
        linearLayoutHome.setOnClickListener(this);
    }

    @Override
    public void onBackPressed() {
        Log.i("wangyan", "getFragmentManager().getBackStackEntryCount()=" + getFragmentManager().getBackStackEntryCount());
        if (getFragmentManager().getBackStackEntryCount() > 1) {
            getFragmentManager().popBackStack();
        } else {
            finish();
            super.onBackPressed();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.linearlayoutHome:
                fragmentPropertyManager.showFragment(new FragmentProperty("Hello 医生", R.layout.fragment_main));
                break;
        }
    }
}